package com.lishe.lishe.lishe.module.myorder.adapter;


import android.app.Activity;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.myorder.bean.Products;

import java.util.List;

/**
 * Created by Bin
 */

public class OrderDetailGoodsAdapter extends RecyclerView.Adapter<OrderDetailGoodsAdapter.ViewHolder> {

    private Activity mContext;
    private List<Products> mList;

    public OrderDetailGoodsAdapter(Activity context, List<Products> list) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_orderdetail_goods, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Products products = mList.get(position);
        holder.goodsCount.setText("x" + products.getNum());
        holder.goodsName.setText(products.getTitle());
        holder.goodsSpec.setText(products.getSpec_info());
        holder.goodsPrice.setText("¥" + products.getPrice());
        if (products.getPrice().equals(products.getOriginal_price())) {
            holder.originalPrice.setVisibility(View.GONE);
        } else {
            holder.originalPrice.setVisibility(View.VISIBLE);
            holder.originalPrice.setText("¥" + products.getOriginal_price());
            holder.originalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        }
        ImageLoaderUtils.displayImage(mContext, products.getPic_path(), holder.goodsImg);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public ImageView goodsImg;
        public TextView goodsName;
        public TextView goodsSpec;
        public TextView goodsPrice;
        public TextView goodsCount;
        public TextView originalPrice;

        ViewHolder(View v) {
            super(v);
            goodsImg = v.findViewById(R.id.goods_img);
            goodsName = v.findViewById(R.id.goods_name);
            goodsSpec = v.findViewById(R.id.goods_spec);
            goodsPrice = v.findViewById(R.id.goods_price);
            goodsCount = v.findViewById(R.id.goods_count);
            originalPrice = v.findViewById(R.id.original_price);
        }
    }
}
